/* 
 *  <copyright file="ProcessFactory.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;

using SobrietyEngine.Common;

namespace SobrietyEngine.Processes
{
    class ProcessFactory
    {
        static private Dictionary<String, IFactoryBuilder<IProcess>> Registry = null;

        public static void Register(String type, IFactoryBuilder<IProcess> builder)
        {
            if (Registry == null)
                Registry = new Dictionary<String, IFactoryBuilder<IProcess>>();
            Registry.Add(type, builder);
        }

        public static void Register(IFactoryBuilder<IProcess> builder)
        {
            Register(builder.GetType(), builder);
        }

        public static IProcess Build(String type, Parameters parms)
        {
            IFactoryBuilder<IProcess> builder;
            if (Registry.TryGetValue(type, out builder))
                return builder.Build(parms);
            //TODO:error warning msg or something
            return default(IProcess);
        }
    }
}
